<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>album管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <!-- 上传图片框样式，不使用上传组件可以删除此样式 -->
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 150px;
            height: 70px;
            line-height: 150px;
            text-align: center;
        }
        .avatar {
            width: 150px;
            height: 70px;
            display: block;
        }

    </style>
</head>
<body class="hold-transition">
<div id="app">

    <div class="content-header">
        <h1>商品<small>商品列表</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>商品</el-breadcrumb-item>
            <el-breadcrumb-item>商品列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <div class="app-container" style="margin-left: 20px; margin-bottom: 20px">
        <div style="margin-bottom: 20px">
            <el-button @click="restoreMany()" size="mini" type="danger" size="small">批量还原</el-button>
            <el-button @click="goBack()" size="mini" type="primary" size="small">返回</el-button>
        </div>
        <div class="box">

            <el-table :data="tableData"
                      border style="width: 100%"
                      @selection-change="handleSelectionChange"
                      ref="multipleTable">
                <el-table-column
                        type="selection"
                        width="55">
                </el-table-column>
                <el-table-column prop="id" label="编号" width="180"></el-table-column>
                <el-table-column prop="image" label="商品图片" width="180">
                    <template slot-scope="scope">
                        <el-image
                                style="width: 100px; height: 100px"
                                :src="scope.row.image"
                                fit="scale-down">
                        </el-image>
                        <!--                <img :src="scope.row.image"/>-->
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="商品名称" width="180"></el-table-column>

                <el-table-column
                        label="操作"  >
                    <template slot-scope="scope">
                        <el-button @click="restoreShop(scope.row.id)" size="mini" type="danger" size="small">还原</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @size-change="fetchData"
                        @current-change="fetchData"
                        :current-page.sync="currentPage"
                        :page-sizes="[10, 20, 30, 40]"
                        :page-size="size"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
        </div>
    </div>


</div>
</body>
<script src="/js/vue.js"></script>
<script src="/js/axios.js"></script>
<script src="/js/elementui.js"></script>
<script src="/js/util.js"></script>
<script>
    new Vue({
        el: '#app',
        data(){
            return {
                tableData: [],
                currentPage: 1,
                total: 10,
                size: 10,
                searchMap: {},
                pojo: {},
                formVisible: false,
                imageUrl: '',
                multipleSelection: [],
                ids: []
            }
        },
        created(){
            this.fetchData();
        },
        methods:{
            restoreMany(){
                axios.post(`/spu/restoreMany.do`,this.ids).then(response => {
                    console.log(response.data);
                });
            },
            handleSelectionChange(val){
                this.ids = [];
                for (const valElement of val) {
                    this.ids.push(valElement.id);
                }
                console.log(this.ids);
            },
            restoreShop(id){
                axios.get(`/spu/restore.do?id=${id}`).then(response => {});
                this.fetchData();
            },
            goBack(id){
                location.href = "goodsList.html";
            },
            fetchData (){
                axios.get(`/spu/findDelPage.do?page=${this.currentPage}&size=${this.size}`,this.searchMap).then(response => {
                    this.tableData = response.data.rows;
                    this.total = response.data.total;
                });
            }
        }
    })
</script>
</html>
